package com.liangxy.zhyl.controller;

import com.github.pagehelper.Page;
import com.liangxy.zhyl.base.PageResponse;
import com.liangxy.zhyl.base.ResponseResult;
import com.liangxy.zhyl.dto.NursingLevelDto;
import com.liangxy.zhyl.entity.NursingLevel;
import com.liangxy.zhyl.service.NursingLevelService;
import com.liangxy.zhyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理等级的控制器
 */
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> listAll() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.listAll();
        return ResponseResult.success(nursingLevelVos);
    }
    @PostMapping("/insert")
    @ApiOperation("添加护理等级")
    public ResponseResult insert(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.insert(nursingLevelDto);
        return ResponseResult.success();
    }
    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>>
    listByPage(@RequestParam(defaultValue = "1", required = false) Integer pageNum, // 页码
               @RequestParam(defaultValue = "10" ) Integer pageSize, // 每页数量
               @RequestParam(required = false) String name, // 名称
               @RequestParam(required = false) Integer status // 状态 0 禁用 1 启用
    ){
        PageResponse<NursingLevelVo> nursingLevelVos = nursingLevelService.page(pageNum,pageSize,name, status);
        return ResponseResult.success(nursingLevelVos);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询详情")
    public ResponseResult<NursingLevelVo> selectById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.selectById(id);
        return ResponseResult.success(nursingLevelVo);
    }
    @PutMapping("update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult delete(@PathVariable Long id){
        nursingLevelService.deleteById(id);
        return ResponseResult.success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理等级")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        nursingLevelService.stopAndStart(id,status);
        return ResponseResult.success();
    }
}
